/*
 * 作者：姚俊
 * 功能：生成论著的action
 * 日期：2015-07-04
 */
package admin.action.count.createFile;

import java.io.UnsupportedEncodingException;

import admin.databaseToExcel.PullTreatiseToExcel;

import teacher.bean.Treatise;
import tools.StringDate;

public class TreatiseCreateAction {
	
	private String date2;
	private Treatise treatise;
	private int direction;


	public String getDate2() {
		return date2;
	}

	public void setDate2(String date2) {
		this.date2 = date2;
	}

	public Treatise getTreatise() {
		return treatise;
	}



	public void setTreatise(Treatise treatise) {
		this.treatise = treatise;
	}
	

	public int getDirection() {
		return direction;
	}



	public void setDirection(int direction) {
		this.direction = direction;
	}
	

	public String execute()
	{
		
		if(this.getTreatise()!=null)
		{
			if(this.getTreatise().getName()==null||this.getTreatise().getName().equals(""))
				this.getTreatise().setName(null);
			else
			{

					try {
						this.getTreatise().setName(new String(this.getTreatise().getName().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

			}
			if(this.getTreatise().getAuthor()==null||this.getTreatise().getAuthor().equals(""))
				this.getTreatise().setAuthor(null);
			else
			{

					try {
						this.getTreatise().setAuthor(new String(this.getTreatise().getAuthor().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
		
			if(this.getTreatise().getBookNum()==null||this.getTreatise().getBookNum().equals(""))
				this.getTreatise().setBookNum(null);
			else
			{

					try {
						this.getTreatise().setBookNum(new String(this.getTreatise().getBookNum().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getTreatise().getPress()==null||this.getTreatise().getPress().equals(""))
				this.getTreatise().setPress(null);
			else
			{

					try {
						this.getTreatise().setPress(new String(this.getTreatise().getPress().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getTreatise().getDate()!=null)
				this.getTreatise().setDate(
						StringDate.StringToDate(
								StringDate.DateToString(
										this.getTreatise().getDate())));
		}
		Treatise tra=new Treatise();
		if(this.getDate2()!=null)
		tra.setDate(StringDate.StringToDate(this.getDate2()));
		PullTreatiseToExcel.treatiseExcel(3, this.getTreatise(),tra,this.getDirection());
		return "succ";
	}

}
